﻿/********************************************************
 * 类名： CodeBLL.cs
 * 功能： 通用生成编号业务层
 *   ver	变更日		作者			变更内容
 * ────────────────────────────────────────
 *   V01.0	2013-12-23	李波			初版
 *
 * Copyright (c) 2013，李波版权所有
 ********************************************************/
using System;
using PSS.DAL.CommonManage;

namespace PSS.BLL.CommonManage
{
    public class CodeBLL
    {
        private readonly CodeDAL _dal = new CodeDAL();
        /// <summary>
        /// 采购单号 CG 20131223 001
        /// </summary>
        public string GetFBillNo()
        {
            var value = string.Empty;
            var date = DateTime.Now.ToString("yyyyMMdd");
            var maxValue = _dal.GetMaxInitPurFBillNo(date);
            if (!string.IsNullOrEmpty(maxValue))
            {
                var temp = maxValue.Substring(maxValue.Length - 3);
                var i = Convert.ToInt32(temp) + 1;
                var result = i.ToString();
                switch (result.Length)
                {
                    case 1:
                        value = "CG" + date + "00" + result;
                        break;
                    case 2:
                        value = "CG" + date + "0" + result;
                        break;
                    case 3:
                        value = "CG" + date + result;
                        break;
                }
            }
            else
            {
                value = "CG" + date + "001";
            }
            return value;
        }
        /// <summary>
        /// 收款单号 SKD 20140208002
        /// </summary>
        public string GetReceiptSingleNo()
        {
            var value = string.Empty;
            var date = DateTime.Now.ToString("yyyyMMdd");
            var maxValue = _dal.GetReceiptSingleNo(date);
            if (!string.IsNullOrEmpty(maxValue))
            {
                var temp = maxValue.Substring(maxValue.Length - 3);
                var i = Convert.ToInt32(temp) + 1;
                var result = i.ToString();
                switch (result.Length)
                {
                    case 1:
                        value = "SKD" + date + "00" + result;
                        break;
                    case 2:
                        value = "SKD" + date + "0" + result;
                        break;
                    case 3:
                        value = "SKD" + date + result;
                        break;
                }
            }
            else
            {
                value = "SKD" + date + "001";
            }
            return value;
        }
        /// <summary>
        /// 付款单号  FKD 20140208001
        /// </summary>
        public string GetSinglePaymentNo()
        {
            var value = string.Empty;
            var date = DateTime.Now.ToString("yyyyMMdd");
            var maxValue = _dal.GetSinglePaymentNo(date);
            if (!string.IsNullOrEmpty(maxValue))
            {
                var temp = maxValue.Substring(maxValue.Length - 3);
                var i = Convert.ToInt32(temp) + 1;
                var result = i.ToString();
                switch (result.Length)
                {
                    case 1:
                        value = "FKD" + date + "00" + result;
                        break;
                    case 2:
                        value = "FKD" + date + "0" + result;
                        break;
                    case 3:
                        value = "FKD" + date + result;
                        break;
                }
            }
            else
            {
                value = "FKD" + date + "001";
            }
            return value;
        }

    }
}
